<html>
<head><meta charset="utf-8"><title>Getting the target tuple · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Getting.20the.20target.20tuple.html">Getting the target tuple</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="220672562"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Getting%20the%20target%20tuple/near/220672562" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Getting.20the.20target.20tuple.html#220672562">(Dec 22 2020 at 09:29)</a>:</h4>
<p>Is it possible to obtain the current target tuple without using a build script?</p>



<a name="220691124"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Getting%20the%20target%20tuple/near/220691124" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Getting.20the.20target.20tuple.html#220691124">(Dec 22 2020 at 13:56)</a>:</h4>
<p>Not that I know of :(</p>



<a name="220847611"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Getting%20the%20target%20tuple/near/220847611" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Getting.20the.20target.20tuple.html#220847611">(Dec 24 2020 at 04:16)</a>:</h4>
<p>You do have to use a build script, and then there's an environment variable with the target.</p>



<a name="220847615"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Getting%20the%20target%20tuple/near/220847615" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Getting.20the.20target.20tuple.html#220847615">(Dec 24 2020 at 04:16)</a>:</h4>
<p>What are you looking to use it for?</p>



<a name="220848054"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Getting%20the%20target%20tuple/near/220848054" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Getting.20the.20target.20tuple.html#220848054">(Dec 24 2020 at 04:28)</a>:</h4>
<p>It might be neat if there were something like <code>cfg_str!(name)</code> giving you a <code>&amp;'static str</code>, just like <code>cfg!(foo)</code> gives a <code>bool</code></p>



<a name="220848061"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Getting%20the%20target%20tuple/near/220848061" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> cuviper <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Getting.20the.20target.20tuple.html#220848061">(Dec 24 2020 at 04:29)</a>:</h4>
<p>Of course not all are strings, and some have multiple values</p>



<a name="220848274"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Getting%20the%20target%20tuple/near/220848274" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Getting.20the.20target.20tuple.html#220848274">(Dec 24 2020 at 04:34)</a>:</h4>
<p>They don't <em>need</em> to return all the same type though (after all, it's a macro, not a function)! We could have <code>cfg_value!(name)</code> (where name is just a textual symbol – i.e., not a string) and then it would return whatever type was appropriate for the value. So <code>cfg_value!(target_triple)</code> could return a value of type <code>(&amp;'static str, &amp;'static str, &amp;'static str)</code> or something.</p>



<a name="220856384"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Getting%20the%20target%20tuple/near/220856384" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Getting.20the.20target.20tuple.html#220856384">(Dec 24 2020 at 08:24)</a>:</h4>
<p><span class="user-mention silent" data-user-id="239881">Josh Triplett</span> <a href="#narrow/stream/122651-general/topic/Getting.20the.20target.20tuple/near/220847615">said</a>:</p>
<blockquote>
<p>What are you looking to use it for?</p>
</blockquote>
<p>Not anything terribly important. In rust-analyzer there's a helper program that produces the release artifacts and I've recently updated it to support cross-compilation by getting a target from the environment. But if you don't pass the target, it will compile the project for the host platform, for convenience. So I wanted the current target tuple to append it to the release artifacts name.</p>



<a name="220856573"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Getting%20the%20target%20tuple/near/220856573" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Getting.20the.20target.20tuple.html#220856573">(Dec 24 2020 at 08:29)</a>:</h4>
<p>Basically to avoid this: <a href="https://github.com/rust-analyzer/rust-analyzer/blob/25a9877/xtask/src/dist.rs#L96-L111">https://github.com/rust-analyzer/rust-analyzer/blob/25a9877/xtask/src/dist.rs#L96-L111</a>.</p>



<a name="220869791"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Getting%20the%20target%20tuple/near/220869791" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Getting.20the.20target.20tuple.html#220869791">(Dec 24 2020 at 13:25)</a>:</h4>
<p>I believe the TARGET environment variable is only set when running the build script. It has been a source of major headaches to me in the past.</p>



<a name="220940429"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Getting%20the%20target%20tuple/near/220940429" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Getting.20the.20target.20tuple.html#220940429">(Dec 25 2020 at 23:16)</a>:</h4>
<p><span class="user-mention" data-user-id="138448">@cuviper</span> I really like that idea. That would also allow for cfg values (including features) with non-boolean values.</p>



<a name="220940432"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Getting%20the%20target%20tuple/near/220940432" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Getting.20the.20target.20tuple.html#220940432">(Dec 25 2020 at 23:16)</a>:</h4>
<p>In <span class="user-group-mention" data-user-group-id="3139">@T-cargo</span>, we've talked about cargo "capabilities", which would be like features but with a value.</p>



<a name="220940439"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Getting%20the%20target%20tuple/near/220940439" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Getting.20the.20target.20tuple.html#220940439">(Dec 25 2020 at 23:17)</a>:</h4>
<p>For instance, a runtime or backend selection from a set of mutually exclusive options.</p>



<a name="220940481"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Getting%20the%20target%20tuple/near/220940481" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Getting.20the.20target.20tuple.html#220940481">(Dec 25 2020 at 23:18)</a>:</h4>
<p>Being able to get that value as a string would allow for more options than just statically comparing it with a string to get a boolean.</p>



<a name="220944316"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Getting%20the%20target%20tuple/near/220944316" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Quy Nguyen <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Getting.20the.20target.20tuple.html#220944316">(Dec 26 2020 at 01:37)</a>:</h4>
<p><span class="user-mention silent" data-user-id="239881">Josh Triplett</span> <a href="#narrow/stream/122651-general/topic/Getting.20the.20target.20tuple/near/220940432">said</a>:</p>
<blockquote>
<p>In <span class="user-group-mention" data-user-group-id="3139">@T-cargo</span>, we've talked about cargo "capabilities", which would be like features but with a value.</p>
</blockquote>
<p>Are these like top-level values, such as <code>link-type</code> for C libs?</p>



<a name="221027367"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/Getting%20the%20target%20tuple/near/221027367" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/Getting.20the.20target.20tuple.html#221027367">(Dec 27 2020 at 23:08)</a>:</h4>
<p><span class="user-mention" data-user-id="303115">@Quy Nguyen</span> They'd have a single value throughout the dependency tree.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>